package net.cloudcodex.client.campaign.view.panel;

import java.util.Date;

import net.cloudcodex.client.campaign.view.CampaignsView.Message;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyDownHandlers;
import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextArea;

public class CampaignConfigPanel extends FlowPanel {

	private SimplePanel headerInfosPanel = new SimplePanel();
	private CampaignInfosPanel infosPanel = new CampaignInfosPanel();
	private FlowPanel descriptionPanel = new FlowPanel();
	private Label descriptionTitle;
	private Button actionButton = new Button();
	private Message message;
	private TextArea descriptionTextArea = new TextArea();

	private Date creationDate = new Date();

	private String description;
	private Button cancelButton = new Button();

	public CampaignConfigPanel() {
		this.add(headerInfosPanel);
		this.add(infosPanel);
		this.add(descriptionPanel);
		this.add(actionButton);
		
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	public void addCampaignInfos(String name, String icon, String game,
			Date creationDate) {
		this.creationDate = creationDate;
		refreshCampaignInfos(name, icon, game);
	}
	
	public void refreshCampaignInfos(String name, String icon, String game){
		infosPanel.addCampaignInfos(name, icon, game);
		
	}

	public void initComponent() {
		headerInfosPanel.add(new Label(message.getStartedOn() + " : "
				+ creationDate.toString()));
		actionButton.setText(message.getModifyButton());
		actionButton.setEnabled(false);
		
		infosPanel.setMessage(message);
		infosPanel.initComponent();
		infosPanel.setWidth("100%");
		descriptionTitle = new Label(message.getPublicDescription());
		descriptionTitle.addStyleName("titlePanel");
		descriptionTextArea.setTitle("description");
		descriptionTextArea.setCharacterWidth(60);
		descriptionTextArea.setVisibleLines(5);
		descriptionPanel.add(descriptionTitle);
		descriptionPanel.add(descriptionTextArea);

	}

	public HasClickHandlers getActionButton() {
		return actionButton;
	}

	public HasKeyDownHandlers getDescriptionTexteAreaKeyDown() {
		return descriptionTextArea;
	}

	public HasKeyUpHandlers getDescriptionTexteAreaKeyUp() {
		return descriptionTextArea;
	}

	public HasKeyDownHandlers getNameTextBoxKeyDown() {
		return infosPanel.getNameTextBoxKeyDown();
	}

	public HasKeyDownHandlers getGameTextBoxKeyDown() {
		return infosPanel.getGameTextBoxKeyDown();
	}

	public HasKeyDownHandlers getIconTextBoxKeyDown() {
		return infosPanel.getIconTextBoxKeyDown();
	}

	public HasKeyUpHandlers getNameTextBoxKeyUp() {
		return infosPanel.getNameTextBoxKeyUp();
	}

	public HasKeyUpHandlers getGameTextBoxKeyUp() {
		return infosPanel.getGameTextBoxKeyUp();
	}

	public HasKeyUpHandlers getIconTextBoxKeyUp() {
		return infosPanel.getIconTextBoxKeyUp();
	}

	public void setActionButtonEnable(boolean enable) {
		actionButton.setEnabled(enable);
	}

	public void removeStartedDateLbl() {
		this.remove(headerInfosPanel);

	}

	public void setActionMessage(String createButton) {
		actionButton.setText(createButton);
		
	}

	public String getCampaignName() {
		return infosPanel.getCampaignName();
	}

	public String getCampaignGame() {
		return infosPanel.getCampaignGame();
	}

	public String getCampaignIcon() {
		return infosPanel.getCampaignIcon() ;
	}

	public String getCampaignDescription() {
		return descriptionTextArea.getText();
	}

	public HasClickHandlers getCancelButton() {
		// TODO Auto-generated method stub
		return cancelButton ;
	}

	public void addCancelButton() {
		this.add(cancelButton);
		cancelButton.setText(message.getCancelButton());
	}
	public void clearView(){
		descriptionTextArea.setText("");
		infosPanel.clearView();
	}
}
